package kded.demo.billnumber;

import kd.bos.dataentity.entity.DynamicObject;
import kd.bos.entity.plugin.AbstractOperationServicePlugIn;
import kd.bos.entity.plugin.AddValidatorsEventArgs;
import kd.bos.entity.plugin.PreparePropertysEventArgs;
import kd.bos.entity.plugin.args.BeginOperationTransactionArgs;
import kd.bos.entity.validate.AbstractValidator;
import kd.bos.servicehelper.coderule.CodeRuleServiceHelper;
import kd.bos.servicehelper.operation.DeleteServiceHelper;

/**
 *caijiasheng
 * 关注点
 * 1、回收编码接口使用
 * 2、回收编码的意义，断号表，防止流水断号
 */
public class Demo1ForDelete extends AbstractOperationServicePlugIn {
    @Override
    public void onPreparePropertys(PreparePropertysEventArgs e) {
        // TODO 在此添加业务逻辑
    }
    @Override
    public void onAddValidators(AddValidatorsEventArgs e) {
        e.addValidator(new AbstractValidator(){
            @Override
            public void validate() {

            }
        });
    }
    @Override
    public void beginOperationTransaction(BeginOperationTransactionArgs e) {
        DynamicObject[] dataEntities = e.getDataEntities();
        if (dataEntities.length < 1){
            return;
        }
        Object[] ids = new Long[dataEntities.length];
        String[] billNos = new String[dataEntities.length];
        for (int i = 0; i < dataEntities.length; i++) {
            DynamicObject dataEntity = dataEntities[i];
            String billNo = dataEntity.getString("billno");
            billNos[i] = billNo;
            ids[i] = dataEntity.getPkValue();
        }
        CodeRuleServiceHelper.recycleBatchNumber("kded_ad_reimb",dataEntities,null,billNos);
        DeleteServiceHelper.delete(dataEntities[0].getDataEntityType(),ids);
    }


}
